# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

_realname=faad2

pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.7
pkgrel=1
pkgdesc="ISO AAC audio decoder (mingw-w64)"
arch=('any')
url="http://www.audiocoding.com/"
groups=("${MINGW_PACKAGE_PREFIX}")
license=('GPL')
options=('staticlibs' 'strip')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("yasm" "${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
source=(http://downloads.sourceforge.net/sourceforge/faac/${_realname}-${pkgver}.tar.bz2
        0001-update-ac.mingw.patch
        0002-no-undefined.mingw.patch
        0003-frontend.mingw.patch
        faad2-2.7-libmp4ff-install-mp4ff_int_types_h.patch
        faad2-2.7-libmp4ff-shared-lib.patch
        faad2-2.7-man1_MANS.patch)
md5sums=('4c332fa23febc0e4648064685a3d4332'
         'c98af0732e6e48bd39724746c9f3cce6'
         '93389ab1afc8788eca22c90be089fe11'
         'cfc4d8f28eedd5ef6330391c52e73f0c'
         'b33354022bc1696a89b3ccc1ab94c54f'
         '72e05448a230d7e6260c3f7f0ff7caf2'
         'a8cee29241a696ab24d010af35b951b8')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/faad2-2.7-libmp4ff-shared-lib.patch"
  patch -p0 -i "${srcdir}/faad2-2.7-libmp4ff-install-mp4ff_int_types_h.patch"
  patch -p1 -i "${srcdir}/faad2-2.7-man1_MANS.patch"
  patch -p1 -i "${srcdir}/0001-update-ac.mingw.patch"
  patch -p1 -i "${srcdir}/0002-no-undefined.mingw.patch"
  patch -p1 -i "${srcdir}/0003-frontend.mingw.patch"
  WANT_AUTOMAKE=latest autoreconf --force --install
}

build() {
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}
  make
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make check
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
